/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.agenda.model.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Ronildo
 */
@Entity
@Table(name = "AM_TB_MEDI_ESPE")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "AmTbMediEspe.findAll", query = "SELECT a FROM AmTbMediEspe a"),
    @NamedQuery(name = "AmTbMediEspe.findByCdEspe", query = "SELECT a FROM AmTbMediEspe a WHERE a.amTbMediEspePK.cdEspe = :cdEspe"),
    @NamedQuery(name = "AmTbMediEspe.findByCdMedi", query = "SELECT a FROM AmTbMediEspe a WHERE a.amTbMediEspePK.cdMedi = :cdMedi")})
public class AmTbMediEspe implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected AmTbMediEspePK amTbMediEspePK;
    @JoinColumn(name = "CD_MEDI", referencedColumnName = "CD_MEDI", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private AmTbMedi amTbMedi;
    @JoinColumn(name = "CD_ESPE", referencedColumnName = "CD_ESPE", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private AmTbEspe amTbEspe;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "amTbMediEspe")
    private Collection<AmTbLocaAtenMedi> amTbLocaAtenMediCollection;

    public AmTbMediEspe() {
    }

    public AmTbMediEspe(AmTbMediEspePK amTbMediEspePK) {
        this.amTbMediEspePK = amTbMediEspePK;
    }

    public AmTbMediEspe(short cdEspe, int cdMedi) {
        this.amTbMediEspePK = new AmTbMediEspePK(cdEspe, cdMedi);
    }

    public AmTbMediEspePK getAmTbMediEspePK() {
        return amTbMediEspePK;
    }

    public void setAmTbMediEspePK(AmTbMediEspePK amTbMediEspePK) {
        this.amTbMediEspePK = amTbMediEspePK;
    }

    public AmTbMedi getAmTbMedi() {
        return amTbMedi;
    }

    public void setAmTbMedi(AmTbMedi amTbMedi) {
        this.amTbMedi = amTbMedi;
    }

    public AmTbEspe getAmTbEspe() {
        return amTbEspe;
    }

    public void setAmTbEspe(AmTbEspe amTbEspe) {
        this.amTbEspe = amTbEspe;
    }

    @XmlTransient
    public Collection<AmTbLocaAtenMedi> getAmTbLocaAtenMediCollection() {
        return amTbLocaAtenMediCollection;
    }

    public void setAmTbLocaAtenMediCollection(Collection<AmTbLocaAtenMedi> amTbLocaAtenMediCollection) {
        this.amTbLocaAtenMediCollection = amTbLocaAtenMediCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (amTbMediEspePK != null ? amTbMediEspePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof AmTbMediEspe)) {
            return false;
        }
        AmTbMediEspe other = (AmTbMediEspe) object;
        if ((this.amTbMediEspePK == null && other.amTbMediEspePK != null) || (this.amTbMediEspePK != null && !this.amTbMediEspePK.equals(other.amTbMediEspePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.agenda.model.entity.AmTbMediEspe[ amTbMediEspePK=" + amTbMediEspePK + " ]";
    }
    
}
